package com.elitel.frame.base.controller;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import com.elitel.frame.base.service.CensusService;
import com.elitel.frame.business.service.TreeConfigService;
import com.elitel.frame.main.entity.BaseStaconfig;
import com.elitel.frame.main.entity.CfgExtsta;
import com.elitel.frame.main.entity.ext.Census;
import com.elitel.frame.main.entity.ext.StaAddons;
import com.elitel.frame.main.entity.vo.PageResponseVo;

/**
 * 报表服务配置类
 * @author dingdaifu
 *
 */
@Controller
@RequestMapping("/system/census")
public class CensusController {

	@Resource
	private CensusService censusServiceImpl;
	@Resource
	private TreeConfigService treeConfigServiceImpl;
	
	@RequestMapping(value="/getCensusXY")
	@ResponseBody
	public Map<String, Object> getCensusXY(HttpServletRequest request){
		String tableName = request.getParameter("key");
		Map<String, Object> map = treeConfigServiceImpl.selectColumnMap(tableName);
		return map;
	}
	
	@RequestMapping(value="/getCensusType")
	@ResponseBody
	public String getCensusType(HttpServletRequest request){
		String column = request.getParameter("key");
		String table = request.getParameter("table");
		String message = censusServiceImpl.getCensusType(column,table);
		return message;
	}
	
	@RequestMapping("/selectcensusone")
	@ResponseBody
	public int selectcensusone(HttpServletRequest request){
		String xx = request.getParameter("sysId");
		int a = censusServiceImpl.selectcensusone(xx);
		return a ;
	}
	
	@RequestMapping(value="/insertField",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Map<String, Object> insertField(@RequestBody CfgExtsta cfgExtsta,HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String message = censusServiceImpl.insertField(cfgExtsta);
		map.put("message", message);
		return map;
	}
	
	@RequestMapping(value="/exitid",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Map<String, Object> exitid(@RequestBody CfgExtsta cfgExtsta,HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String message = censusServiceImpl.exitid(cfgExtsta.getGuid());
		map.put("message", message);
		return map;
	}
	
	@RequestMapping(value="/selectTableName")
	@ResponseBody
	public Map<String, Object> selectTableName(HttpServletRequest request){
		String dbKey = request.getParameter("dbKey");
		List<String> list= censusServiceImpl.selectTableName(dbKey);
		Map<String, Object> map = censusServiceImpl.selectTableNameMap(list);
		return map;
	}
	
	@RequestMapping(value="/selectTableNames")
	@ResponseBody
	public Map<String, Object> selectTableNames(HttpServletRequest request){
		String dbKey = request.getParameter("dbKey");
		List<String> list= censusServiceImpl.selectTableNames(dbKey);
		Map<String, Object> map = censusServiceImpl.selectTableMap(list);
		return map;
	}
	
	@RequestMapping(value="/insertDataClick",method =RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public String insertDataClick(@RequestBody List<StaAddons> staAddons,HttpServletRequest request){
		
		String message = censusServiceImpl.insertDataClick(staAddons);
		return message;
	}
	
	@RequestMapping(value="/deleteField")
	@ResponseBody
	public Map<String, Object> deleteField(HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String guid = request.getParameter("keys");
		String message = censusServiceImpl.deleteField(guid);
		map.put("message", message);
		return map;
	}
	
	@RequestMapping(value="/updateField",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Map<String, Object> updateField(@RequestBody CfgExtsta cfgExtsta,HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String message = censusServiceImpl.updateField(cfgExtsta);
		map.put("message", message);
		return map;
	}
	@RequestMapping(value="/selectOneField")
	@ResponseBody
	public CfgExtsta selectOneField(HttpServletRequest request){
		String guid = request.getParameter("key");
		CfgExtsta cfgExtsta = censusServiceImpl.selectOneField(guid);
		return cfgExtsta;
	}
	
	@RequestMapping(value="/selectField")
	@ResponseBody
	public List<Census> selectField(HttpServletRequest request){
		List<Census> list = censusServiceImpl.selectField();
		return list;
	}
	
	@RequestMapping(value="/insertStaConfig")
	@ResponseBody
	public Map<String, Object> insertStaConfig(@RequestBody BaseStaconfig baseStaconfig, HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String message = censusServiceImpl.insertStaConfig(baseStaconfig);
		map.put("message", message);
		return map;
	}
	
	@RequestMapping(value="/deleteStaConfig")
	@ResponseBody
	public Map<String, Object> deleteStaConfig(HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String guid = request.getParameter("keys");
		String message = censusServiceImpl.deleteStaConfig(guid);
		map.put("message", message);
		return map;
	}
	
	@RequestMapping(value="/updateStaConfig",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Map<String, Object> updateStaConfig(@RequestBody BaseStaconfig baseStaconfig,HttpServletRequest request){
		Map<String, Object> map = new HashMap<String, Object>();
		String message = censusServiceImpl.updateStaConfig(baseStaconfig);
		map.put("message", message);
		return map;
	}
	
	@RequestMapping(value="/selectOneStaConfig")
	@ResponseBody
	public BaseStaconfig selectOneStaConfig(HttpServletRequest request){
		String guid = request.getParameter("key");
		BaseStaconfig baseStaconfig = censusServiceImpl.selectOneStaConfig(guid);
		return baseStaconfig;
	}
	
	@RequestMapping(value="/selectWher")
	@ResponseBody
	public List<String> selectWher(HttpServletRequest request){
		String guid = request.getParameter("key");
		List<String> list = censusServiceImpl.selectWher(guid);
		return list;
	}
	
	@RequestMapping(value="/selectWheMapr")
	@ResponseBody
	public Map<String, Object> selectWheMapr(HttpServletRequest request){
		String sdb = request.getParameter("sdb");
		String guid = request.getParameter("guid");
		Map<String, Object> map = censusServiceImpl.selectWheMapr(sdb,guid);
		return map;
	}
	@RequestMapping(value="/selectcolumning")
	@ResponseBody
	public String selectcolumning(HttpServletRequest request){
		String sdb = request.getParameter("sdb");
		String guid = request.getParameter("guid");
		String message = censusServiceImpl.selectcolumning(sdb,guid);
		return message;
	}
	@RequestMapping(value="/selectcolumned")
	@ResponseBody
	public List<String> selectcolumned(HttpServletRequest request){
		String guid = request.getParameter("key");
		List<String> list = censusServiceImpl.selectcolumned(guid);
		return list;
	}
	
	@RequestMapping(value="/selectTableStaConfig")
	@ResponseBody
	public PageResponseVo<BaseStaconfig> selectTableStaConfig(HttpServletRequest request){
		String guid = request.getParameter("sysId");
		String pageNo = request.getParameter("pageNo");
		String pageSize = request.getParameter("pageSize");
		PageResponseVo<BaseStaconfig> pageResponseVo = censusServiceImpl.selectTableStaConfig(guid,pageNo,pageSize);
		return pageResponseVo;
	}
	
	@RequestMapping(value="/selectColumnList")
	@ResponseBody
	public List<StaAddons> selectColumnList(HttpServletRequest request){
		String guid = request.getParameter("sysId");
		String sguid = request.getParameter("keys");
		List<StaAddons> list = censusServiceImpl.selectColumnList(guid,sguid);
		return list;
	}
	@RequestMapping(value="/selectColumnTableBiao")
	@ResponseBody
	public List<StaAddons> selectColumnTableBiao(HttpServletRequest request){
		String guid = request.getParameter("sysId");
		String sguid = request.getParameter("keys");
		List<StaAddons> list = censusServiceImpl.selectColumnTableBiao(guid,sguid);
		return list;
	}
	
	@RequestMapping(value="/getkeys")
	@ResponseBody
	public String getkeys(HttpServletRequest request){
		String guid = request.getParameter("sysId");
		String biaoid = censusServiceImpl.getkeys(guid);
		return biaoid;
	}
	
	
	@RequestMapping(value="/selectTableStaConfigOne")
	@ResponseBody
	public BaseStaconfig selectTableStaConfigOne(HttpServletRequest request){
		String guid = request.getParameter("sysId");
		BaseStaconfig baseStaconfig = censusServiceImpl.selectTableStaConfigOne(guid);
		return baseStaconfig;
	}
	
	@RequestMapping(value="/selectColumnType")
	@ResponseBody
	public Map<String, String> selectColumnType(HttpServletRequest request){
		String valu = request.getParameter("val");
		String keys = request.getParameter("keys");
		Map<String, String> map  = censusServiceImpl.selectColumnType(valu,keys);
		return map;
	}
}
